package com.example.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/28 15:31
 */
public class ResponseUtils {
    private ResponseUtils() {}

    public static String ok() {
        return ok(null);
    }

    public static String ok(Object data) {
        HashMap<Object, Object> res = new HashMap<>(3);
        res.put("code", 200);
        res.put("msg", "ok");
        res.put("data", data);
        return FastJsonUtils.objectToString(res);
    }

    public static String fail() {
        return fail("error");
    }
    public static String fail(String msg) {
        return fail(-1, msg, null);
    }
    public static String unlogin() {
        return fail(501, "未登录", null);
    }
    public static String serious() {
        return fail(502, "系统内部错误", null);
    }

    public static String fail(int code, String msg, Object data) {
        Map<String, Object> res = new HashMap<>();
        res.put("code", code);
        res.put("msg", msg);
        res.put("data", data);
        return FastJsonUtils.objectToString(res);
    }

}
